<?php
require "../config.php";
$user_name = $_POST['user'];
$pwd = md5($_POST['pwd']);
$email = $_POST['email'];
$conn = mysqli_connect($MySqlHost, $MySqlUser, $MySqlPwd, $MySqlDatabaseName);
if (mysqli_connect_errno($conn))
{
    echo json_encode(array("status"=>500, "msg" => "连接 MySQL 失败: " . mysqli_connect_error()));
}
mysqli_query($conn, "set character set 'utf8'");//读库
mysqli_query($conn, "set names 'utf8'");//写库
$res = mysqli_query($conn,"SELECT * FROM users WHERE user = '$user_name'");
if(mysqli_num_rows($res)>0){
    echo json_encode(array("status" => 500, "msg" => "用户已存在"));
}else{
    $res = mysqli_query($conn,"INSERT INTO users (user,pwd,email) VALUES('$user_name','$pwd','$email')");
    echo json_encode(array("status" => 200, "msg" => "注册成功"));
}
